<!DOCTYPE html>
<html lang="">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>登入 - webIM</title>
  <link rel="stylesheet" type="text/css" href="../layui/css/layui.css">
  <link rel="stylesheet" type="text/css" href="../css/login.css">
  <link rel="stylesheet" type="text/css" href="../css/admin.css">
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2>LayIM 即时通讯系统</h2>
    </div>
    <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
        <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
      </div>

      <div class="layui-form-item" style="margin-bottom: 20px;">
        <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
        <a th:href="@{/user/test}" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码</a>
      </div>
      <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
      </div>
      <div class="layui-form-item layadmin-user-jump-change">
        <label>没有账号 ？</label>
        <a th:href="@{/user/reg}" class="layadmin-link">加入我们</a>
      </div>
    </div>
  </div>
</div>

<script src="/layui/layui.js"></script>
<script>
  layui.use(['layer', 'form', 'jquery'], function() {
    //layui组件
    const layer = layui.layer
            , $ = layui.jquery
            , form = layui.form

    form.on('submit(LAY-user-login-submit)', function(obj){
      $.ajax({
        url:"/login?username="
                +obj.field.username
                +"&password="
                +obj.field.password,
        type:"POST",
        success:function(data) {
          if(data.code === 0){
            layer.msg(data.msg, {
              offset: '15px'
              ,icon: 1
              ,time: 1000
            }, function(){
              location.href = '../index';
            });
          }else {
            layer.msg(data.msg, {
              icon: 2,time: 1000
            });
          }
        },
        error:function() {
          layer.msg("服务器错误,请稍后再试！",{
            icon: 2, time: 1000
          });
        }
      });
    });
  })
</script>

</body>
</html>